package cn.jdy.plugins.wap;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.jdy.authority.entity.Organ;
import cn.jdy.authority.entity.User;
import cn.jdy.authority.entity.UserRole;
import cn.jdy.common.ctrl.BaseCtrl;
import cn.jdy.framework.log.BaseLog;
import cn.jdy.framework.util.DateUtil;
import cn.jdy.framework.util.NginxPurgeCacheUtil;
import cn.jdy.plugins.entity.EvaluationRecord;
import cn.jdy.plugins.entity.EvaluationRecordService;
import cn.jdy.plugins.entity.ExamQuestions;
import cn.jdy.plugins.entity.WatchUser;
import cn.jdy.plugins.service.ExamQuestionsService;


/**
 * @desc   测评记录控制操作类
 * @author nignqian
 * @date   2016-7-21
 */
@Controller
@RequestMapping("/evaluationRecord")
public class EvaluationRecordCtrl extends BaseCtrl {
	@Autowired
	private EvaluationRecordService evaluationRecordService;
	
	
	@Autowired
	private ExamQuestionsService examQuestionsService;
	
	
	
	
	
	 
	
	 
	 
	 
	/**
	 * 导出测评记录
	 * @param evaluationRecord
	 * @param fromDate
	 * @param toDate
	 * @param model
	 * @return
	 */
	@RequestMapping("/addEvaluationRecord")
	@ResponseBody
	public Map<String, Object> addEvaluationRecord(EvaluationRecord evaluationRecord) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();

		Map<String, Object> watchUser = (Map<String, Object>) session.getAttribute("watchUser");
		try {
			evaluationRecord.setUserId(String.valueOf(watchUser.get("openid")));
			evaluationRecord.setLiveId(Long.valueOf(watchUser.get("liveId")+""));
			evaluationRecord.setCreateTime(DateUtil.getCurrentDate(DateUtil._DEFAULT2));

				evaluationRecordService.save(evaluationRecord);
				
				jsonMap.put("msg", "200");
		} catch (Exception e) {

			jsonMap.put("msg", "400");
		}
		return jsonMap;
	    
	}	

	/*投票数据*/
	@RequestMapping("/toupiaoCount")
	@ResponseBody
	public  Map<String, Object> toupiaoCount(String id) {
		Map<String, Object> jsonMap = new HashMap<String, Object>();

		try {
		
			Map<String, Object> m = examQuestionsService.evaluationRecord(Long.valueOf(id));
			jsonMap.put("datename",m.get("name"));
			jsonMap.put("datezs",m.get("zs"));
				
		
		} catch (Exception e) {

			jsonMap.put("msg", "400");
		}
		return jsonMap;
	}
	
}
